cmake_minimum_required(VERSION 3.16.1)

project(samples)

if(NOT EXISTS "${CMAKE_SOURCE_DIR}/.dev_env")
    message(FATAL_ERROR "Please run env prepare script ./prepare_dev_env.sh first!")
endif()

# Read the file into a list of lines
file(STRINGS "${CMAKE_SOURCE_DIR}/.dev_env" DEV_ENV_LINES)

# Process each line
foreach(line IN LISTS DEV_ENV_LINES)
    string(STRIP "${line}" line)
    if(line MATCHES "^([^=]+)=(.*)$")
        set(var_name "${CMAKE_MATCH_1}")
        set(var_value "${CMAKE_MATCH_2}")
        # Remove any leading/trailing whitespace
        string(STRIP "${var_name}" var_name)
        string(STRIP "${var_value}" var_value)
        # Set the variable
        set(${var_name} ${var_value})
    endif()
endforeach()

set(ASCEND_INSTALL_PATH ${ASCEND_INSTALL_PATH}/latest)
set(ASCEND_LIB_DIR ${ASCEND_INSTALL_PATH}/lib64)
message(STATUS "ASCEND_LIB_DIR = ${ASCEND_LIB_DIR}")

set(CMAKE_CXX_STANDARD 17)
add_compile_definitions(
        _GLIBCXX_USE_CXX11_ABI=0
        google=ascend_private
)

include_directories(${ASCEND_INSTALL_PATH}/include)

# inner header files, remove later
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/base/metadef)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/base/metadef/inc)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/base/metadef/inc/graph)
include(${CMAKE_CURRENT_SOURCE_DIR}/base/metadef/cmake/intf_pub_linux.cmake)

set(CMAKE_PREFIX_PATH  ${ASCEND_LIB_DIR} ${CMAKE_PREFIX_PATH})

find_library(C_SEC_LIB NAMES c_sec REQUIRED)
find_library(GRAPH_LIB NAMES graph REQUIRED)
find_library(GRAPH_BASE_LIB NAMES graph_base REQUIRED)
find_library(ERROR_MANAGER_LIB NAMES error_manager REQUIRED)
find_library(SYMBOLIC_LIB NAMES aihac_symbolizer REQUIRED)

add_executable(sample main.cpp dump.cpp)
target_link_libraries(sample PRIVATE ${GRAPH_LIB} ${GRAPH_BASE_LIB})
target_include_directories(sample PRIVATE ${ASCEND_INSTALL_PATH}/include)

